#include <stdbool.h>
#include <stdint.h>

#include "inc/tm4c123gh6pm.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_adc.h"
#include "inc/hw_types.h"
#include "inc/hw_timer.h"
#include "inc/hw_nvic.h"

#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/adc.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/systick.h"

#include "utils/uartstdio.h"

#include "source/dht11Lib/dht11.h"
#include "source/TimerDelay/timerdelay.h"


/*******************************************************************************
 * GLOBAL VARIABLES
 */
 
tDHT11 dht_test = {GPIO_PORTA_BASE,GPIO_PIN_2,0,0,0,0};
tDHT11 dht_test1 = {GPIO_PORTA_BASE,GPIO_PIN_7,0,0,0,0};

void ConfigureUART(void);

/*******************************************************************************
 * MAIN
 */
int main(){
	SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN);
	ConfigureUART();
  DHT11_Init(dht_test);
  TimerDelayConfigure(); //it's declared if you use timerdelay library
	UARTprintf("comport opened !\n");
	while(1){
		while(!DHT11_GetData(&dht_test)){} 
		
			UARTprintf("Temperature--0: %d *C, Humidity--0: %d percent  \n",\
			dht_test.IntTemperature,dht_test.IntHumidity);
		
		while(!DHT11_GetData(&dht_test1)){}
		
			UARTprintf("Temperature--1: %d *C, Humidity--1: %d percent  \n",\
			dht_test1.IntTemperature,dht_test1.IntHumidity);
		
	}
	
}

void ConfigureUART(void)
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    UARTStdioConfig(0, 115200, 16000000);
}
